package com.ddl.controller.core;

import com.ddl.common.exception.ResultModel;
import com.ddl.service.IUserFieldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author dudianbo
 * @ClassName: ${CLASSNAME}
 * @Description: ${DESCRIPTION}
 * @date 2018/11/17
 */
@RestController
@RequestMapping(value = "/app/field")
public class UserFieldController {

     @Autowired
     IUserFieldService iUserFieldService;

    /**
     * 用户田地
     * @param request
     * @return
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/userField")
    public ResultModel userField(@RequestBody Map<String, Object> map,HttpServletRequest request) {
        String userId=map.get("userId").toString();
        return iUserFieldService.userField(userId);
    }
    /**
     * 种田地
     * @param request
     * @return
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/speciesField")
    public ResultModel speciesField(HttpServletRequest request) {
        String userId=request.getHeader("userId");
        return iUserFieldService.speciesField(userId);
    }
    /**
     * 偷金币
     * @param request
     * @return
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/stealingGold")
    public ResultModel stealingGold(@RequestBody Map<String, Object> map,HttpServletRequest request) {
        String userId=request.getHeader("userId");
        Integer seedId=Integer.parseInt(map.get("seedId").toString());
        return iUserFieldService.stealingGold(userId,seedId);
    }
    /**
     * 偷金币校验
     * @param request
     * @return
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/beforeStealingGold")
    public ResultModel beforeStealingGold(@RequestBody Map<String, Object> map,HttpServletRequest request) {
        String userId=request.getHeader("userId");
        String firendId=map.get("friendId").toString();
        return iUserFieldService.beforeStealingGold(userId,firendId);
    }
    /**
     * 使用道具
     * @param request
     * @return
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/useStage")
    public ResultModel useStage(@RequestBody Map<String, Object> map,HttpServletRequest request) {
        String userId=request.getHeader("userId");
        String type=map.get("type").toString();
        String firendId=map.get("friendId")==null?null:map.get("friendId").toString();
        return iUserFieldService.useStage(userId,type,firendId);
    }
    /**
     * 铲地
     * @param request
     * @return
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/chandi")
    public ResultModel chandi(@RequestBody Map<String, Object> map,HttpServletRequest request) {
        String userId=request.getHeader("userId");
        Integer seedId=Integer.parseInt(map.get("seedId").toString());
        return iUserFieldService.chandi(userId,seedId);
    }
}
